﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;

namespace OrderGen
{
    class Generate100
    {
       public class GetSocket
       {
            private static Socket ConnectSocket(string server, int port)
            {
            Socket socket = null;
            IPHostEntry hostEntry = null;
        
            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);

            // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach(IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipAdress = new IPEndPoint(address, port);
                Socket tempSocket = 
                    new Socket(ipAdress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                tempSocket.Connect(ipAdress);

                if(tempSocket.Connected)
                {
                    socket = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }
        }
        return socket;
    }

    
      
       
            
    }
    
    public static void Main(string[] args) 
    {
       private static string SocketSend(string server, int port) 
       {     
        // Create a socket connection with the specified server and port.
        Socket socket = ConnectSocket(server, port);

        if (socket == null)
            return ("Connection failed");
           
            int a = 101;
            Random rdm = new Random();
            
            //randomize
            double bidPrice; 
            int bidQuantity; //range 10-100
            double offerPrice; 
            int offerQuantity;
            //BuySell = 0 for Buy; BuySell = 1 for sell
            int  BuySell;

            //do not randomize
            string service = "UTIL";
            string option = "NO"; //everything is futures, no options
            string orderType = "Market"; //just a market order for now.  now other order types

            string[] stream;
            stream = new string[a];
            stream[0]   = "<EOF>|41.00|01000|Option|None|00.00|BUY|ADMIN|Client |TimeStamp|OriginatingIPAddress|<SOH>";
            stream[1]   = "<EOF>|38.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[2]   = "<EOF>|40.50|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[3]   = "<EOF>|41.00|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[4]   = "<EOF>|41.50|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[5]   = "<EOF>|39.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[6]   = "<EOF>|39.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[7]   = "<EOF>|40.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[8]   = "<EOF>|44.00|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[9]   = "<EOF>|38.50|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[10]  = "<EOF>|42.00|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[11]  = "<EOF>|41.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[12]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[13]  = "<EOF>|41.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[14]  = "<EOF>|41.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[15]  = "<EOF>|42.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[16]  = "<EOF>|37.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[17]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[18]  = "<EOF>|40.50|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[19]  = "<EOF>|38.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[20]  = "<EOF>|37.50|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[21]  = "<EOF>|42.00|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[22]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[23]  = "<EOF>|42.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[24]  = "<EOF>|43.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[25]  = "<EOF>|44.50|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[26]  = "<EOF>|41.00|01000|Option|Stop|39.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[27]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[28]  = "<EOF>|29.00|01000|No    |Stop|27.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[29]  = "<EOF>|33.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[30]  = "<EOF>|41.00|01000|Option|None|00.00|BUY|ADMIN|Client |TimeStamp|098.220.195.211:5123|<SOH>";
            stream[31]  = "<EOF>|38.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[32]  = "<EOF>|40.50|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[33]  = "<EOF>|41.00|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[34]  = "<EOF>|41.50|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[35]  = "<EOF>|39.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[36]  = "<EOF>|39.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[37]  = "<EOF>|40.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[38]  = "<EOF>|44.00|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[39]  = "<EOF>|38.50|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[40]  = "<EOF>|42.00|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[41]  = "<EOF>|41.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[42]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[43]  = "<EOF>|41.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[44]  = "<EOF>|41.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[45]  = "<EOF>|42.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[46]  = "<EOF>|37.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[47]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[48]  = "<EOF>|40.50|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[49]  = "<EOF>|38.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[50]  = "<EOF>|37.50|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[51]  = "<EOF>|42.00|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[52]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[53]  = "<EOF>|42.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[54]  = "<EOF>|43.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[55]  = "<EOF>|44.50|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[56]  = "<EOF>|41.00|01000|Option|Stop|39.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[57]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[58]  = "<EOF>|29.00|01000|No    |Stop|27.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[59]  = "<EOF>|33.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[60]  = "<EOF>|41.00|01000|Option|None|00.00|BUY|ADMIN|Client |TimeStamp|098.220.195.211:5123|<SOH>";
            stream[61]  = "<EOF>|38.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[62]  = "<EOF>|40.50|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[63]  = "<EOF>|41.00|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[64]  = "<EOF>|41.50|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[65]  = "<EOF>|39.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[66]  = "<EOF>|39.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[67]  = "<EOF>|40.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[68]  = "<EOF>|44.00|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[69]  = "<EOF>|38.50|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[70]  = "<EOF>|42.00|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[71]  = "<EOF>|41.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[72]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[73]  = "<EOF>|41.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[74]  = "<EOF>|41.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[75]  = "<EOF>|42.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[76]  = "<EOF>|37.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[77]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[78]  = "<EOF>|40.50|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[79]  = "<EOF>|38.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[80]  = "<EOF>|37.50|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[81]  = "<EOF>|42.00|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[82]  = "<EOF>|41.00|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[83]  = "<EOF>|42.50|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[84]  = "<EOF>|43.00|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[85]  = "<EOF>|44.50|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[86]  = "<EOF>|41.00|01000|Option|Stop|39.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[87]  = "<EOF>|39.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[88]  = "<EOF>|29.00|01000|No    |Stop|27.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[89]  = "<EOF>|33.00|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[90]  = "<EOF>|41.00|01000|Option|None|00.00|BUY|ADMIN|Client |TimeStamp|098.220.195.211:5123|<SOH>";
            stream[91]  = "<EOF>|38.50|01000|No    |Stop|45.00|BUY|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[92]  = "<EOF>|40.50|01000|Option|None|00.00|SEL|UTIL |ClientE|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[93]  = "<EOF>|41.00|01000|No    |Stop|43.50|BUY|ADMIN|ClientK|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[94]  = "<EOF>|41.50|01000|No    |None|00.00|SEL|UTIL |ClientA|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[95]  = "<EOF>|39.00|01000|Option|None|00.00|SEL|TRAN |ClientC|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[96]  = "<EOF>|39.50|01000|Option|Stop|33.00|BUY|ADMIN|ClientW|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[97]  = "<EOF>|40.00|01000|Option|None|00.00|BUY|TRAN |ClientB|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[98]  = "<EOF>|44.00|01000|No    |Stop|41.50|SEL|UTIL |ClientF|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[99]  = "<EOF>|38.50|01000|Option|None|45.00|BUY|ADMIN|ClientG|TimeStamp|098.220.195.211:5123|<SOH>";
            stream[100] = "<EOF>|42.00|01000|Option|None|00.00|BUY|ADMIN|ClientA|TimeStamp|098.220.195.211:5123|<SOH>";

            string BS;
            try
            {   // Do the date streams need to be coered into bytes?  <-------------------
                for (int counter = 0; counter < stream.Length; counter++)
                {
                   bidPrice = rdm.Next(45.00f, 50.00f);
                   offerPrice = rdm.Next(45.00f, 50.00f);
                   bidQuantity = rdm.Next(1, 100);
                   offerQuantity = rdm.Next(1,100);
                   BuySell = rdm.Next(0,1);

                   //if(BuySell == 1)
                   //   BS = "Buy";
                   //else
                   //   BS = "Sell";

                   //Console.Write("{0}", stream[counter]);
                   Console.Write(server + bidPrice + bidQuantity + offerPrice + offerQuantity);
                }
            }
            catch (InvalidCastException e)
            {
                ;  // if the "real NumGem finds an error, what should it do?  <----------------
            }
        } 
        
    } 
}

